/**
 *Author: chenxiaoyu
 *Date: 2018/4/9
 *Email: 1524904743@qq.com
 *
 */

var managerModule= angular.module('managerModule', []);

/*
* 管理中心主页
* */
managerModule.controller('managerCtrl', [
    '$scope',
    '$rootScope',
    function ($scope, $rootScope) {
        $scope.tabsData= [];
        $rootScope.$on('managerOpenTabs', function (event, args) {
            var stat= true;
            angular.forEach($scope.tabsData, function (item, k) {
                if (item.id == args.id){
                    stat= false;
                    throw '遍历中断';
                }
            })
            if (stat && !!args.url){
                $scope.tabsData.push(args);
            }
        });

    }
]);

managerModule.controller('knowledgeReportCtrl', [
    '$scope',
    function ($scope) {
        $scope.defaultShow= true;

        $scope.datetimeStart= {
            value: '',
            text: '请输入开始时间'
        };
        $scope.datetimeEnd= {
            value: '',
            text: '请输入结束时间'
        };

        /************附件上传  start************************/
        var attachType = ['doc','docx','xls','xlsx','txt','pdf','jpg','html','mht','htm','bmp','ppt','pptx','ppsm','msg'];
        var uploderurl = '/FileUpload/knowReportAttarchments';
        $scope.uploaderSetting={
            uploader: uploderurl,
            size_limit: 1024*1024*10,
            input_file_name: 'attach',
            messages: {
                type: '不支持的文件类型！',
                empty: '请选择上传文件！',
                size: '上传文件大小超过10m的限制！'
            },
            fn: 'uploadCallback',
            allow_ext_ll: attachType,
            fnBeforeUpload: 'uploadBeforeCheck'
        };
        //上传附件之前的检查
        $scope.uploadBeforeCheck = function(file_name){
            var i=true;
            var name=file_name.substr(0,file_name.indexOf(".",0));//截取附件名
            _.each($scope.knowAttachmentFiles,function(item){
                if(item.name==name){
                    uiTips.alert("附件列表已上传同名文件！");
                    i=false;
                }
            });

            if(i){
                $('#loading').text("文件上传中...");
                $('#loading, #loading-block').show();
            }
            return i;
        };
        // 上传附件的回调函数
        $scope.uploadCallback=function(fileName,returnData){
            var returnDto = returnData.fileDTO;
            $scope.knowAttachmentFiles.push(returnDto);
            uiTips.unloading();
        };
        /************附件上传  end************************/

        // 表头
        $scope.thead= ['系列', '任务编号', '任务类型', '任务主题', '紧急程度', '提交人/行政机构', '提交时间', '操作'];

        $scope.pager= {
            pageNum: 1,
            pageSize: 1,
            totalCount: 5
        }

        $scope.changePage= function (cp, event) {
            $scope.pager.pageNum= cp;
        }

    }
])